package com.base.myproject.client.HR.analysis;

import com.extjs.gxt.charts.client.Chart;
import com.extjs.gxt.charts.client.model.ChartModel;
import com.extjs.gxt.charts.client.model.axis.Label;
import com.extjs.gxt.charts.client.model.axis.XAxis;
import com.extjs.gxt.charts.client.model.axis.YAxis;
import com.extjs.gxt.charts.client.model.charts.BarChart;
import com.extjs.gxt.charts.client.model.charts.BarChart.BarStyle;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.google.gwt.user.client.Random;

public class JoinDateAnslysis extends ContentPanel {
	
	private static final String[] Years = new String[] {
	      "1年", "2年", "3年", "4年", "5年", "6年", "7年", "8年", "9年", "10年", "11年", "12年","13年","14年以上"};
	public JoinDateAnslysis(){
		this.setHeaderVisible(false);
		setWidth(500);
		setHeight(280);
		getChart();
	}
	
	public void  getChart(){
		String url = "chart/open-flash-chart.swf"; 
		
		Chart chart = new Chart(url);  
		chart.setBorders(true);  
		chart.setChartModel(getChartModel()); 
		add(chart);
	}
	
	public ChartModel getChartModel(){
		ChartModel cm = new ChartModel("入职年限统计图", "font-size: 14px; font-family: Verdana;"); 
		cm.setBackgroundColour("-1"); 
		
		XAxis xa = new XAxis();
	    for (String m : getYears(14)) {  
	    	Label l = new Label(m, 45);  
			l.setSize(10);  
			l.setColour("#000000");  
			xa.addLabels(l);  
		}  
	    xa.setGridColour("-1");  
	    cm.setXAxis(xa);  
	    
	    YAxis ya = new YAxis();  
	    ya.setSteps(1);  
	    ya.setMax(150);  
	    ya.setGridColour("#8888FF");  
	    cm.setYAxis(ya);  
	    
	    BarChart bchart = new BarChart(BarStyle.GLASS);  
	    bchart.setColour("#FF00CC");  
	    bchart.setTooltip("共#val#人");  
	    for (int t = 0; t < 14; t++) {  
	    	bchart.addBars(new BarChart.Bar(Random.nextInt(50) + 50, "#8888FF"));  
	    	//bchart.addValues(Random.nextInt(50) + 50);  
	    }  
	    cm.addChartConfig(bchart);  
	    return cm;  
	}
	
	public String[] getYears(int n) {
	    String[] years = new String[n];
	    for (int i = 0; i < n; i++)
	      years[i] = Years[i];
	    return years;
	}
}
